﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZX.WebApp.WorkFlow
{
    public partial class WorkFlowSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 流程类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlCaption_SelectedIndexChanged(object sender, EventArgs e)
        {
            string captions = string.Empty; //流程类型
            captions = ddlCaption.SelectedValue; //流程类型
            Oper_DateTime.Disabled = false;//
            Oper_DateEndTime.Disabled = false;
            Start_Date.Disabled = false;//开始时间
            Start_EndDate.Disabled = false;
            taskStartTime.Disabled = false; //到达时间
            taskEndTime.Disabled = false;
            Report_Date.Disabled = false; //结束时间
            Report_EndDate.Disabled = false;
            switch (captions)
            {
                case "1": //待办
                    Oper_DateTime.Disabled = true;//处理时间
                    Oper_DateEndTime.Disabled = true;//处理时间
                    Start_Date.Disabled = true;//开始时间
                    Start_EndDate.Disabled = true;
                    Report_Date.Disabled = true; //结束时间
                    Report_EndDate.Disabled = true;
                    taskStartTime.Disabled = true;//到达时间
                    taskEndTime.Disabled = true;
                    break;
                case "2": //已完成流程
                    Oper_DateTime.Disabled = true;//处理时间
                    Oper_DateEndTime.Disabled = true;
                    Start_Date.Disabled = true;//开始时间
                    Start_EndDate.Disabled = true;
                    taskStartTime.Disabled = true; //结束时间
                    taskEndTime.Disabled = true;
                    break;
                case "3"://我的申请
                    Report_Date.Disabled = true; //结束时间
                    Report_EndDate.Disabled = true;
                    taskStartTime.Disabled = true; //到达时间
                    taskEndTime.Disabled = true;
                    Start_Date.Disabled = true;//开始时间
                    Start_EndDate.Disabled = true;
                    break;
                case "4": //我的审批(未完成)
                     Start_Date.Disabled = true;//开始时间
                     Start_EndDate.Disabled = true;
                     taskStartTime.Disabled = true; //到达时间
                     taskEndTime.Disabled = true;
                     Report_Date.Disabled = true; //结束时间
                     Report_EndDate.Disabled = true;
                
                    break;
                case "5": //我的审批(已完成)
                     Start_Date.Disabled = true;//开始时间
                     Start_EndDate.Disabled = true;
                     taskStartTime.Disabled = true; //到达时间
                     taskEndTime.Disabled = true;
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 紧急程度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlPriority_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strSql = string.Empty;
            string caption = string.Empty;//流程类型
            string workFlowNo = string.Empty; //流程编号
            string flowCaption = string.Empty;//流程名称
            string priority = string.Empty; //紧急程度
            string customId = string.Empty; //创建人
            string operDateTime = string.Empty; //处理时间
            string operDateEndTime = string.Empty;

            string startDate = string.Empty;//开始时间
            string startEndDate = string.Empty;

            string reportDate = string.Empty;//结束时间
            string reportEndDate = string.Empty;

            string startTime = string.Empty;//到达时间
            string startEndTiem = string.Empty;
            caption = ddlCaption.SelectedValue; //流程类型
            if (caption != "0" && caption !="")
            {
                workFlowNo = this.txbWorkFlowNo.Text; //流程编号
                flowCaption = this.txtFlowCaption.Text;//流程名称
                priority = ddlPriority.Text; //紧急程度
                customId = txtCustomId.Value; //创建人

                operDateTime = Oper_DateTime.Value; //处理时间
                operDateEndTime = Oper_DateEndTime.Value;

                startDate = Start_Date.Value;//开始时间
                startEndDate = Start_EndDate.Value;

                reportDate = Report_Date.Value;//结束时间
                reportEndDate = Report_EndDate.Value;

                startTime = taskStartTime.Value; //到达时间
                startEndTiem = taskEndTime.Value;
                switch (caption)
                {
                    case "1": //待办任务
                        if (workFlowNo != "")  //流程编号
                        {
                            if (strSql == "")
                            {
                                strSql = "WorkFlowNo='"+workFlowNo+"'";
                            }
                            else 
                            {
                                strSql += " and  WorkFlowNo='"+workFlowNo+"'";
                            }
                        }
                        if (flowCaption != "") //流程名称
                        {
                            if (strSql == "")
                            {
                                strSql = "FlowInstanceCaption like '%" + flowCaption + "%'";
                            }
                            else
                            {
                                strSql += " and  FlowInstanceCaption like '%" + flowCaption + "%'";
                            }
                        }
                        if (priority != "") //紧急程度
                        {
                            if (strSql == "")
                            {
                                strSql = "Priority='"+priority+"'";
                            }
                            else
                            {
                                strSql += " and  Priority='"+priority+"'";
                            }
                        }
                        if (customId != "") //创建人
                        {
                            if (strSql == "")
                            {
                                strSql = "FlowInstanceCaption='" + customId + "'";
                            }
                            else
                            {
                                strSql += " and  FlowInstanceCaption='" + customId + "'";
                            }
                        }
                        if (startTime != "") //到达时间
                        {
                            if (strSql == "")
                            {
                                strSql = "taskStartTime >'"+startTime+"' and taskStartTime < '"+startEndTiem+"'";
                            }
                            else
                            {
                                strSql += " and  taskStartTime >'"+startTime+"' and taskStartTime < '"+startEndTiem+"'";
                            }
                        }
                        if (strSql != "")
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=V_HF_TaskInstanceView&functionID=8E3F1DF7-DCA8-4110-9446-5E8F9EAC9AAF&condition=" + strSql + "&order=taskStartTime desc";
                        }
                        else
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=V_HF_TaskInstanceView&functionID=8E3F1DF7-DCA8-4110-9446-5E8F9EAC9AAF&order=taskStartTime desc";
                        }
                        break;
                    case "2": //已完成流程
                         if (workFlowNo != "")  //流程编号
                        {
                            if (strSql == "")
                            {
                                strSql = "WorkFlowNo='"+workFlowNo+"'";
                            }
                            else 
                            {
                                strSql += " and  WorkFlowNo='"+workFlowNo+"'";
                            }
                        }
                         if (flowCaption != "") //流程名称
                         {
                             if (strSql == "")
                             {
                                 strSql = "FlowCaptions like '%"+flowCaption+"%'";
                             }
                             else
                             {
                                 strSql += " and  FlowCaptions like '%" + flowCaption + "%'";
                             }
                         }
                        if (priority != "") //紧急程度
                        {
                            if (strSql == "")
                            {
                                strSql = "Priority='"+priority+"'";
                            }
                            else
                            {
                                strSql += " and  Priority='"+priority+"'";
                            }
                        }
                        if (customId != "") //创建人
                        {
                            if (strSql == "")
                            {
                                strSql = "OperContentText='"+customId+"'";
                            }
                            else
                            {
                                strSql += " and  OperContentText='"+customId+"'";
                            }
                        }
                        if (reportDate != "")//结束时间
                        {
                            if (strSql == "")
                            {
                                strSql = "EndTime >'" + reportDate + "' and EndTime < '" + reportEndDate + "'";
                            }
                            else
                            {
                                strSql += " and  EndTime >'" + reportDate + "' and EndTime < '" + reportEndDate + "'";
                            }
                        }
                        if (strSql != "")
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowInstanceView&functionID=05da08d8-d3d7-41a2-ab0a-c4cc276dc97d&condition=" + strSql + " and Status='3'&order=EndTime desc";
                        }
                        else 
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowInstanceView&functionID=05da08d8-d3d7-41a2-ab0a-c4cc276dc97d&condition=Status='3'&order=EndTime desc";
                        }
                        break;
                    case "3": //我的申请
                         if (workFlowNo != "")  //流程编号
                        {
                            if (strSql == "")
                            {
                                strSql = "WorkFlowNo='"+workFlowNo+"'";
                            }
                            else 
                            {
                                strSql += " and  WorkFlowNo='"+workFlowNo+"'";
                            }
                        }
                         if (flowCaption != "") //流程名称
                         {
                             if (strSql == "")
                             {
                                 strSql = "FlowCaptions like '%" + flowCaption + "%'";
                             }
                             else
                             {
                                 strSql += " and  FlowCaptions like '%"+flowCaption+"%'";
                             }
                         }
                        if (priority != "") //紧急程度
                        {
                            if (strSql == "")
                            {
                                strSql = "Priority='"+priority+"'";
                            }
                            else
                            {
                                strSql += " and  Priority='"+priority+"'";
                            }
                        }
                        if (customId != "") //创建人
                        {
                            if (strSql == "")
                            {
                                strSql = "OperContentText='"+customId+"'";
                            }
                            else
                            {
                                strSql += " and  OperContentText='"+customId+"'";
                            }
                        }
                        if (operDateTime != "")
                        {
                            if (strSql == "")
                            {
                                strSql = "OperDateTime >'" + operDateTime + "' and OperDateTime <'" + operDateEndTime + "'";
                            }
                            else
                            {
                                strSql += " and  OperDateTime >'" + operDateTime + "' and OperDateTime <'" + operDateEndTime + "'";
                            }
                        }
                        if (strSql != "")
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowApplicationView&functionID=818d19f0-ffbf-4fc8-a624-ded200c3b151&condition=" + strSql + "&order=OperDateTime desc";
                        }
                        else 
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowApplicationView&functionID=818d19f0-ffbf-4fc8-a624-ded200c3b151&order=OperDateTime desc";
                        }
                        break;
                    case "4": //我的审批(未完成)
                         if (workFlowNo != "")  //流程编号
                        {
                            if (strSql == "")
                            {
                                strSql = "WorkFlowNo='"+workFlowNo+"'";
                            }
                            else 
                            {
                                strSql += " and  WorkFlowNo='"+workFlowNo+"'";
                            }
                        }
                         if (flowCaption != "") //流程名称
                         {
                             if (strSql == "")
                             {
                                 strSql = "FlowCaptions like '%"+flowCaption+"%'";
                             }
                             else
                             {
                                 strSql += " and  FlowCaptions like '%"+flowCaption+"%'";
                             }
                         }
                        if (priority != "") //紧急程度
                        {
                            if (strSql == "")
                            {
                                strSql = "Priority='"+priority+"'";
                            }
                            else
                            {
                                strSql += " and  Priority='"+priority+"'";
                            }
                        }
                        if (customId != "") //创建人
                        {
                            if (strSql == "")
                            {
                                strSql = "OperContentText='"+customId+"'";
                            }
                            else
                            {
                                strSql += " and  OperContentText='"+customId+"'";
                            }
                        }
                        if (operDateTime != "")//处理时间
                        {
                            if (strSql == "")
                            {
                                strSql = "OperDateTime >'" + operDateTime + "' and OperDateTime <'" + operDateEndTime + "'";
                            }
                            else
                            {
                                strSql += " and OperDateTime >'" + operDateTime + "' and OperDateTime <'" + operDateEndTime + "'";
                            }
                        }
                        if (strSql != "")
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowApproveView&functionID=4d2286ce-ba11-49c5-8ab2-d6b8b5ad613f&condition=" + strSql + " and Status<>'3'&order=OperDateTime desc";
                        }
                        else 
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowApproveView&functionID=4d2286ce-ba11-49c5-8ab2-d6b8b5ad613f&condition=Status<>'3'&order=OperDateTime desc";
                        }
                        break;
                    case "5": //我的审批(已完成)
                         if (workFlowNo != "")  //流程编号
                        {
                            if (strSql == "")
                            {
                                strSql = "WorkFlowNo='" + workFlowNo + "'";
                            }
                            else 
                            {
                                strSql += " and  WorkFlowNo='" + workFlowNo + "'";
                            }
                        }
                        if (flowCaption != "") //流程名称
                        {
                            if (strSql == "")
                            {
                                strSql = "FlowCaptions like '%" + flowCaption + "%'";
                            }
                            else
                            {
                                strSql += " and  FlowCaptions like '%"+flowCaption+"%'";
                            }
                        }
                        if (priority != "") //紧急程度
                        {
                            if (strSql == "")
                            {
                                strSql = "Priority='"+priority+"'";
                            }
                            else
                            {
                                strSql += " and  Priority='"+priority+"'";
                            }
                        }
                        if (customId != "") //创建人
                        {
                            if (strSql == "")
                            {
                                strSql = "OperContentText='" + customId + "'";
                            }
                            else
                            {
                                strSql += " and  OperContentText='" + customId + "'";
                            }
                        }
                        if (operDateTime != "")
                        {
                            if (strSql == "")
                            {
                                strSql = "OperDateTime >'" + operDateTime + "' and OperDateTime <'" + operDateEndTime + "'";
                            }
                            else
                            {
                                strSql += " and  OperDateTime >'" + operDateTime + "' and OperDateTime <'" + operDateEndTime + "'";
                            }
                        }
                        if (reportDate != "")
                        {
                            if (strSql == "")
                            {
                                strSql = "EndTime >'" + reportDate + "' and EndTime <'" + reportEndDate + "'";
                            }
                            else
                            {
                                strSql += " and  EndTime >'" + reportDate + "' and EndTime <'" + reportEndDate + "'";
                            }
                        }
                        if (strSql != "")
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowApproveView&functionID=F2EACCB3-5CA4-47BC-B4E2-E4F51545FE63&condition=" + strSql + " and Status='3'&order=EndTime desc";
                        }
                        else 
                        {
                            strSql = "~/Extend/YUIList.aspx?entity=HF_WorkFlowApproveView&functionID=F2EACCB3-5CA4-47BC-B4E2-E4F51545FE63&condition=Status='3'&order=EndTime desc";
                        }
                        break;
                    default:
                        break;
                }
                Response.Redirect(strSql);
            }
            else 
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "Search", "<script>alert('请选择流程类型')</script>");
            }
        }
    }
}